﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WLFramework.Json;
using WLFramework.Common;
using System.Diagnostics;

namespace UnitTest1
{
    [TestClass]
    public class UnitTest2
    {
        private class JsonMenu
        {
            public int m_id { get; set; }
        }

        private class JsonData
        {
            public int r_id { get; set; }
            public JsonMenu[] menus { get; set; }
        }

        [TestMethod]
        public void TestMethod1()
        {
            string json = "{\"r_id\":1, \"numbers\":[{\"m_id\":2}, {\"m_id\":3}]}";

            JsonData t = JSON.Instance.ToObject<JsonData>(json);

            Assert.AreEqual(t.r_id, 1);

            //JSON.Instance.RegisterCustomType(typeof(test), null, input =>
            //{
            //    return null;
            //});
        }

        [TestMethod]
        public void TestMethod2()
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();
            
            string s1 = "";
            string s2 = "              ";
            string s3 = "  hello    m";
            string s4 = "\t\r\n  \r";

            for (int i = 0; i < 100000; i++)
            {
                StringHelper.IsNullOrWhiteSpace(s1);
                StringHelper.IsNullOrWhiteSpace(s2);
                StringHelper.IsNullOrWhiteSpace(s3);
                StringHelper.IsNullOrWhiteSpace(s4);
            }

            Assert.Inconclusive("takes {0} ms", watch.ElapsedMilliseconds);
            

            //Assert.IsTrue(StringHelper.IsNullOrWhiteSpace(s1));
            //Assert.IsTrue(StringHelper.IsNullOrWhiteSpace(s2));
            //Assert.IsFalse(StringHelper.IsNullOrWhiteSpace(s3));
            //Assert.IsTrue(StringHelper.IsNullOrWhiteSpace(s4));
        }
    }
}
